package com.atguigu.springcloud.payment.controller;

import com.atguigu.springcloud.framework.common.api.ApiResult;
import com.atguigu.springcloud.payment.entity.Payment;
import com.atguigu.springcloud.payment.service.PaymentService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
 * @author lenovo
 * @version 1.0
 * @date 2020/11/11 11:07
 */
@Api(value = "支付")
@Slf4j
@RestController
@RequestMapping("payment")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PaymentController {

    final private PaymentService paymentService;


    @Value("${server.port}")
    private Integer port;

    @PostMapping("create")
    public ApiResult create(@RequestBody Payment payment) {
        boolean save = paymentService.save(payment);
        log.info("插入的结果【{}】", save);
        return ApiResult.result(save);
    }


    @GetMapping("get/{id}")
    public ApiResult query(@PathVariable Long id) {
        Payment payment = paymentService.getById(id);
        log.info("查询的结果【id={}】【{}】", id, payment);
        return ApiResult.ok(payment).setMessage("端口：" + port);
    }

    @GetMapping("zk")
    public ApiResult zk() {
        return ApiResult.ok("spring cloud with zookeeper: " + port + " " + UUID.randomUUID());
    }

}
